/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.gui;

import Server.domain.Player;
import Server.domain.User;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author Ripper
 */
public class UserReviewPanel extends ServerPanel
{
    private JTree overview;
    private DefaultMutableTreeNode top;
    
    private JPanel container;
    
    public UserReviewPanel(ServerWindow sw)
    {
        super(sw);
        setLayout(new BorderLayout());
        
        top = new DefaultMutableTreeNode("User Overview");
        overview = new JTree(top);
        
        container = new JPanel(new BorderLayout());
        {
            JScrollPane scroller = new JScrollPane(overview);
            
            container.add(scroller, BorderLayout.CENTER);
        }
        add(container, BorderLayout.CENTER);
        
        
    }
    
    public void refreshData()
    {
        container.removeAll();
        
        top.removeAllChildren();
        
        for(User u: getServerDomainController().getUsers())
        {
            int plrCnt = u.getPlayers().size();
            String userInformation = "user: "+u.getUsername()+" ("+u.getFirstName()+" "+u.getLastName()+")  -  "+plrCnt+" "+
                    (plrCnt == 1?"player":"players");
            DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(userInformation);
            
            for(Player p: u.getPlayers())
            {
                String playerInformation = "player: "+p.getPlayerName()+" (lvl: "+p.getLevel()+")";
                DefaultMutableTreeNode pdmtn = new DefaultMutableTreeNode(playerInformation);
                
                dmtn.add(pdmtn);
            }
            
            top.add(dmtn);
        }
        overview = new JTree(top);
        
        JScrollPane scroller = new JScrollPane(overview);
        container.add(scroller);
    }
}
